using System;
using System.Collections.Generic;
using Blog.Testing;
using MbUnit.Framework;
using Rhino.Mocks;

namespace Blog.Domain.Repositories
{
  [Concern(typeof(PostRepository))]
  [TestFixture]
  public class when_looking_up_posts_for_a_specifc_date_that_contains_actual_posts  : SpecificationContext<IPostRepository>
  {
    private IPost firstPost;
    private IPost secondPost;
    private DateTime monday;
    private IPost thirdPost;
    private DateTime tuesday;
    private IEnumerable<IPost> results;

    protected override IPostRepository EstablishContext()
    {
      firstPost = Stub<IPost>();
      secondPost = Stub<IPost>();
      thirdPost = Stub<IPost>();

      monday = new DateTime(2008, 1, 1);
      tuesday = new DateTime(2008, 1, 2);

      firstPost.Stub(post => post.DateWasPublished).Return(monday);
      secondPost.Stub(post => post.DateWasPublished).Return(monday);
      thirdPost.Stub(post => post.DateWasPublished).Return(tuesday);

      return new PostRepository(new List<IPost>{firstPost, secondPost, thirdPost});
    }

    protected override void BecauseOf()
    {
      results = sut.FindAllPostsPublishedOn(monday);
    }

    [Test]
    public void should_be_able_to_retrieve_posts_for_that_date()
    {
      results.ShouldContain(firstPost);
      results.ShouldContain(secondPost);
    }
  }

  [Concern(typeof(PostRepository))]
  [TestFixture]
  public class when_looking_up_posts_for_a_specifc_date_and_no_actual_posts : SpecificationContext<IPostRepository>
  {
    private IPost firstPost;
    private IPost secondPost;
    private DateTime monday;
    private DateTime tuesday;
    private IEnumerable<IPost> results;

    protected override IPostRepository EstablishContext()
    {
      firstPost = Stub<IPost>();
      secondPost = Stub<IPost>();

      monday = new DateTime(2008, 1, 1);
      tuesday = new DateTime(2005, 1, 1);

      firstPost.Stub(post => post.DateWasPublished).Return(monday);
      secondPost.Stub(post => post.DateWasPublished).Return(monday);

      return new PostRepository(new List<IPost> { firstPost, secondPost });
    }

    protected override void BecauseOf()
    {
      results = sut.FindAllPostsPublishedOn(tuesday);
    }

    [Test]
    public void should_be_able_to_retrieve_posts_for_that_date()
    {
      results.ShouldNotContain(firstPost);
      results.ShouldNotContain(secondPost);
    }
  }

}